package com.yungam.other.iot_controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yungam.common.bean.alarm_config.AlarmConfig;
import com.yungam.common.response.RetDTO;
import com.yungam.common.service.AlarmConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 同步工艺阈值
 */
@Slf4j
@RestController
@RequestMapping("/imcs_to_iot")
public class UpdateProcessThresholdController {

    @Resource
    private AlarmConfigService alarmConfigService;

    @PostMapping("/updateProcessThreshold")
    public RetDTO<?> updateProcessThreshold(@RequestBody List<AlarmConfig> list) {
        alarmConfigService.remove(new QueryWrapper<>());
        for (AlarmConfig alarmConfig : list) {
            alarmConfig.setId(null);
        }
        alarmConfigService.saveBatch(list);
        return RetDTO.success();
    }

}
